package service.impl;

import commons.BaiduAIUtil;
import service.AIFaceService;

/**
 * service.impl
 * User: 邱
 * Date: 2024/12/21 16:32
 * Description:
 * Version: V1.0
 */
public class AIFaceServiceImpl implements AIFaceService {

    private BaiduAIUtil baiduAiUtils = new BaiduAIUtil();
    @Override
    public String faceLogin(StringBuffer image) {
        //需要处理一下 "所需要的xxx"
        String img = image.substring(image.indexOf(",") + 1, image.length());
        //人脸搜索
        String userInfo = baiduAiUtils.search(img);
        return userInfo;
    }

    @Override
    public String faceRegister(StringBuffer image, String userInfo, String phoneNum) {
        String img = image.substring(image.indexOf(",") + 1, image.length());
        //人脸检测
        Boolean isFace = baiduAiUtils.detect(img);
        if (isFace){
            //人脸注册
            Boolean isSuccess = baiduAiUtils.addUser(img, userInfo, phoneNum);
            if (isSuccess)
                return "注册成功";
            else
                return "注册失败";
        }
        return "没有人脸或遮挡过多";
    }
}
